﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Gencode.Gengui.Display;
using Gencode.Controls.CollapsibleControl;
using Gencode.PrsCommon.App;

namespace Personalplaner.Modules.Dienstplan
{
    public partial class DiensplanSelector : DisplayableViewControler
    {
        public DienstplanContainer PartnerContent
        {
            get
            {
                return PartnerView as DienstplanContainer;
            }
        }

		//PlanSelect plSel;
        public PlanSelect PlanSel
        {
            get
            {
                return planSelectionItem;
            }
        }

		//ColorSelect colSel;
        public ColorSelect ColorSel
        {
            get
            {
                return colorSelectionItem;
            }
        }

		//DienstSelect diSel;
        public DienstSelect DienstSel
        {
            get
            {
				return dienstSelectionItem;
            }
        }

        public DiensplanSelector()
        {
            InitializeComponent();

			this.planSelectionItem.Controler = this;
			this.planSelectionItem.Header.ListHeaderStateChanged += new ListHeaderStateChangedEventHandler(PlanSelector_ListHeaderStateChanged);

			//plSel = new PlanSelect(this);
			//collapsibleControl.Nodes.Add(plSel);
			//plSel.Header.ListHeaderStateChanged += new ListHeaderStateChangedEventHandler(PlanSelector_ListHeaderStateChanged);
			//plSel.Header.IsCollapsed = true;

			colorSelectionItem.Controler = this;
			colorSelectionItem.Header.ListHeaderStateChanged += new ListHeaderStateChangedEventHandler(ColorSelector_ListHeaderStateChanged);
			//colSel = new ColorSelect(this);
			//collapsibleControl.Nodes.Add(colSel);
			//colSel.Header.ListHeaderStateChanged += new ListHeaderStateChangedEventHandler(ColorSelector_ListHeaderStateChanged);
			//colSel.Header.IsCollapsed = true;

			dienstSelectionItem.Controler = this;
			dienstSelectionItem.Header.ListHeaderStateChanged += new ListHeaderStateChangedEventHandler(DienstSelector_ListHeaderStateChanged);
			//diSel = new DienstSelect(this);
			//collapsibleControl.Nodes.Add(diSel);
			//diSel.Header.ListHeaderStateChanged += new ListHeaderStateChangedEventHandler(DienstSelector_ListHeaderStateChanged);
			//diSel.Header.IsCollapsed = true;
			//diSel.StrechStyle = Gencode.Controls.CollapsibleControl.CollapsibleItemStrechStyle.Strech;
        }

		private void PlanSelector_ListHeaderStateChanged(object sender, ListHeaderStateChangedEventArgs e)
		{
			CallForSizeChange();
		}

		private void ColorSelector_ListHeaderStateChanged(object sender, ListHeaderStateChangedEventArgs e)
		{
			if (e.State == ListHeaderState.Collapsed)
			{
				PlanUtil.UseColor = false;
			}
			else
			{
				PlanUtil.UseColor = true;
			}

			CallForSizeChange();
		}

		private void DienstSelector_ListHeaderStateChanged(object sender, ListHeaderStateChangedEventArgs e)
		{
			if (e.State == ListHeaderState.Collapsed)
			{
				PlanUtil.UseDienst = false;
			}
			else
			{
				PlanUtil.UseDienst = true;
			}

			CallForSizeChange();
		}

		public override int CalculateHeight(int maxHeight)
		{
			//base.CalculateHeight(maxHeight);
			int h = this.Margin.Top + this.Margin.Bottom;
			foreach (CollapsibleItem item in collapsibleControl.Nodes)
			{
				h += (item.Header.Height + item.Margin.Top + item.Margin.Bottom);
				if (item.Header.IsCollapsed)
				{
					if (item is DienstSelect)
					{
						int htmp = (item as DienstSelect).ControlHeight;
						if (htmp > maxHeight)
							h = maxHeight;
						else
							//h = maxHeight;
							h += htmp;

						break;
					}
					else
						h += item.Height + item.Margin.Top + item.Margin.Bottom;
				}
			}

			return h;
		}
    }
}
